package com.lvmama.rhino.common.utils.sharedvariable

import org.apache.spark.AccumulatorParam

import scala.collection.mutable

/**
  * Created by yuanxiaofeng on 2016/5/10.
  */
object iAccumulator{
  implicit object MapAccumulator extends AccumulatorParam[mutable.Map[String, Long]]{
    override def addInPlace(r1: mutable.Map[String, Long], r2: mutable.Map[String, Long]): mutable.Map[String, Long] = {
      for (m <- r2){
        if (r1.contains(m._1)){
          r1(m._1) += m._2
        } else {
          r1 += m
        }
      }
      r1
    }

    override def zero(initialValue: mutable.Map[String, Long]): mutable.Map[String, Long] = mutable.Map()
  }
}
